package main.java.com.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ForwardServlet",urlPatterns = {"/forwardc"})
public class ForwardServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("forwardServlet...");
        System.out.println(response.getCharacterEncoding());//ISO-8859-1 默认
        response.setHeader("Content-Type","text/html;charset=UTF-8");//设置浏览器的编码解析格式也是UTF-8，否则有的游览器默认是GBK
        response.setCharacterEncoding("UTF-8");//设置服务器响应回数据的编码格式
        response.getWriter().println("我是中国人");
    }
}
